var that
const db = wx.cloud.database();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    openid: '',
    content: '',
    user: {},
    textContent:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this;
    that.data.id = options.id;
    that.data.openid = options.openid;
    that.jugdeUserLogin();
  },
  /**
   * 判断用户是否登录
   */
  jugdeUserLogin: function(event) {
    // 查看是否授权
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: function(res) {

              that.data.user = res.userInfo;
              console.log(that.data.user)
            }
          })
        }
      }
    })
  },

  bindKeyInput(e) {
    that.data.content = e.detail.value;
    console.log("内容：" + that.data.content)

  },

 save:function(event){
   db.collection('replay').add({
     data:{
      content: that.data.content,
      date: new Date(),
      t_id: that.data.id,
      u_id: that.data.openid,
      user: that.data.user,
     },
     success: function(res) {
      wx.showToast({
        title: '发射成功',
      })
      setTimeout(function() {
        wx.navigateBack({
          url: "../detail/detail?id=" + that.data.id + "&openid=" + that.data.openid
        })
      }, 1500)

    },
    fail: console.error
   })
 }
  


})